Protected WithEvents ddlItemTemplate As System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlAlternateTemplate As System.Web.UI.WebControls.DropDownList
Protected WithEvents btnCustom As System.Web.UI.WebControls.Button
Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Load template names in the two DropDownList controls
If Not Me.IsPostBack Then
' Load template names in a hashtable.
Dim ht As New Hashtable(4)
ht.Add("Black on yellow", "Black_on_yellow.ascx")
ht.Add("Blue on orange", "Blue_on_orange.ascx")
ht.Add("Blue on white", "Blue_on_white.ascx")
ht.Add("White on blue", "White_on_blue.ascx")
' Load these values into the two DropDownList controls
ddlItemTemplate.DataSource = ht
ddlItemTemplate.DataTextField = "Key"
ddlItemTemplate.DataValueField = "Value"
ddlItemTemplate.DataBind()
ddlAlternateTemplate.DataSource = ht
ddlAlternateTemplate.DataTextField = "Key"
ddlAlternateTemplate.DataValueField = "Value"
ddlAlternateTemplate.DataBind()
' ensure no item is selected
ddlItemTemplate.SelectedIndex = -1
ddlAlternateTemplate.SelectedIndex = -1
BindDataList()
End If
End Sub
' Display some titles from the Pubs database
Sub BindDataList()
Dim cn As New OleDbConnection(OledbPubsConnString)
cn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM Titles", cn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
DataList1.DataSource = dr
DataList1.DataBind()
dr.Close()
cn.Close()
End Sub
' Load a new .ascx from file
Private Sub ddlItemTemplate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlItemTemplate.SelectedIndexChanged, ddlAlternateTemplate.SelectedIndexChanged
' Get the name of the template file.
Dim file As String = ddlItemTemplate.SelectedItem.Value
' Load the template and rebind the DataList control.
DataList1.ItemTemplate = Me.LoadTemplate(file)
' Get the name of the alternate template file.
file = ddlAlternateTemplate.SelectedItem.Value()
' Load the template and rebind the DataList control.